package com.jiantong.user.impl.service;

import com.google.common.collect.Maps;
import com.jiantong.user.impl.dao.DepartmentExtendDao;
import com.jiantong.user.model.DepartmentExtend;
import com.jiantong.user.service.DepartmentExtendReadService;
import io.terminus.boot.rpc.common.annotation.RpcProvider;
import io.terminus.common.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
 * Created by mz on 11/5/17.
 *
 */
@Slf4j
@Service
@RpcProvider
public class DepartmentExtendReadServiceImpl implements DepartmentExtendReadService{

    private final DepartmentExtendDao departmentExtendDao;

    @Autowired
    public DepartmentExtendReadServiceImpl(DepartmentExtendDao departmentExtendDao){
        this.departmentExtendDao = departmentExtendDao;
    }

    @Override
    public Response<DepartmentExtend> findByDepartmentExtend(Long factoryOrPointId,Integer factoryOrPointType) {
        try{
            Map<String ,Object> map = Maps.newHashMap();
            if(factoryOrPointId != null){
                map.put("factoryOrPointId",factoryOrPointId);
            }
            if(factoryOrPointType != null){
                map.put("factoryOrPointType",factoryOrPointType);
            }
            DepartmentExtend departmentExtend = departmentExtendDao.findDepartmentExtendBy(map);
            return Response.ok(departmentExtend);
        }catch (Exception e){
            log.error("failed to find DepartmentExtend");
            return Response.fail("failed to find DepartmentExtend");
        }
    }
}
